package fmanganiello.tests.javatests.hibernate;

import java.util.Date;
import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;

@SuppressWarnings("deprecation")
public class Main {
	public static void main(String[] args) {
		EntityManagerFactory entityManagerFactory = Persistence.createEntityManagerFactory("fmanganiello.tests.javatests.hibernate");
		EntityManager entityManager = entityManagerFactory.createEntityManager();
		
		entityManager.getTransaction().begin();
		entityManager.persist(new User("Fabio", "Manganiello", new Date(86, 10, 17)));
		entityManager.getTransaction().commit();
		
		List<User> users = entityManager.createQuery("FROM User WHERE id=1", User.class).getResultList();
		for (User user : users) {
			System.out.println(user.getFirstname());
		}
		
		entityManager.close();
	}
}
